package cn.gcjxsc.repository.order;

import cn.gcjxsc.common.consts.OrderDiscr;
import cn.gcjxsc.entity.mall.BaseOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface BaseOrderRepository extends JpaRepository<BaseOrder, Integer>, JpaSpecificationExecutor<BaseOrder>{

    BaseOrder findBySn(String sn);

    BaseOrder findBySnAndDiscr(String sn, OrderDiscr discr);

    @Query(value = "select a.* from rw_orders a inner join rw_mall_order_info b on a.id = b.order_id where a.pay_status = 1 and a.status = 4 and b.ship_time < :times  ORDER BY a.created ASC limit 0, :max", nativeQuery = true)
    List<BaseOrder> queryUncompleteAfter7days(@Param("times") long times, @Param("max") int max);
}
